/*
 * 百度在线网络技术（北京）有限公司拥有本软件版权2021并保留所有权利。
 * Copyright 2021, Baidu.com,Inc 2:Baidu Online Network Technology (Beijing) Co.,Ltd,
 * All rights reserved.
 */

package com.azdebugit.tree.tree.queue;


/*链队列实现类*/
public class LinkedQueue<T> {
 
	private Node<T> front;
	private Node<T> rear;
	private int size;
 
	public LinkedQueue() {
		Node<T> node = new Node<T>(null, null);
		front = node;
		rear = node;
	}
 
	// 入队操作
	public void enQueue(T data) {
		Node<T> node = new Node<T>(data, null);
		rear.setNextNode(node);
		rear = node;
		size++;
	}
 
	// 出队操作
	public T deQueue() {
		if(front == rear) {
			System.out.println("链队为空");
			return null;
		}
        Node<T> node=front.getNextNode();
        T t=node.getData();
        front.setNextNode(node.getNextNode());
        if(node.getNextNode()==null)
        	rear=front;
        size--;
        return t;
	}
 
	// 获取队列的对头元素
	public T getQueueTop() {
		return front.getNextNode().getData();
	}
 
	// 判断链队列是否为空
	public boolean isEmpty() {
		if (size == 0)
			return false;
		return true;
	}

	public Node<T> getFront() {
		return front;
	}

	public void setFront(Node<T> front) {
		this.front = front;
	}

	public Node<T> getRear() {
		return rear;
	}

	public void setRear(Node<T> rear) {
		this.rear = rear;
	}

	public int getSize() {
		return size;
	}

	public void setSize(int size) {
		this.size = size;
	}
}